package com.arron.principle.inversion.improve2;

public class DependencyInversion {
    public static void main(String[] args) {
        TVBlackWhite tvBlackWhite = new TVBlackWhite();
        OpenAndClose openAndClose = new OpenAndClose(tvBlackWhite);
        openAndClose.open();
    }
}

interface IOpenAndClose{
    void open ();
}

interface ITV{
    void play();
}

class TVBlackWhite implements ITV{
    @Override
    public void play() {
        System.out.println("黑白电视播放。。。");
    }
}

//方式2 通过构造方法依赖传递
class OpenAndClose implements IOpenAndClose{
    private ITV itv;
    public OpenAndClose(ITV itv) {
        this.itv=itv;
    }
    @Override
    public void open() {
        itv.play();
    }
}
